package On_class.L0331;

import java.util.*;

public class Demo0331_2 {
    public static void main(String[] args) {
        System.out.println("输入一句话");
        Scanner sc=new Scanner(System.in);
        String s1=sc.nextLine();

        String[] s=s1.split(" ");
        HashMap<String,Integer> map=new HashMap<String ,Integer>();

        for (int i=0;i<s.length;i++){
            if(map.containsKey(s[i])){
                Integer value=map.get(s[i]);
                map.put(s[i],value+1);
            }else {
                map.put(s[i],1);
            }
        }
        System.out.println("统计结果:");

        Iterator<String>iterator=map.keySet().iterator();
        while (iterator.hasNext()){
            /*迭代器中取出的元素是：键key*/
            String key=iterator.next();
            Integer value = map.get(key);
            System.out.println(key+"--"+value);
        }
    }
}
